package com.yunglu.pa02;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class PA02Activity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first_view);
		Button buttonRed = (Button) findViewById(R.id.button1);
		Button buttonGreen = (Button) findViewById(R.id.button2);
		Button buttonBlue = (Button) findViewById(R.id.button3);
		Button buttonWhite = (Button) findViewById(R.id.button4);
		ImageView imageACM = (ImageView) findViewById(R.id.imageView1);
		buttonRed.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				changeView();
			}
		});
		buttonGreen.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				changeView();
			}
		});
		buttonBlue.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				changeView();
			}
		});
		buttonWhite.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				changeView();
			}
		});
		imageACM.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				changeView();
				return true;
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.first_view, menu);
		return true;
	}

	private void changeView() {
		// selectedColor = color;
		setContentView(R.layout.second_view);
		ImageButton buttonIEEE = (ImageButton) findViewById(R.id.imageButton1);
		ImageButton buttonPurdue = (ImageButton) findViewById(R.id.imageButton2);
		buttonIEEE.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startBrower(getString(R.string.IEEEURL));
			}
		});
		buttonPurdue.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startBrower(getString(R.string.PurdueURL));
			}
		});
	}
	private void startBrower(String URL) {
		Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
		startActivity(browserIntent);
	}
	
}
